<?php

function reequipment_adminapi_createshipping($args)
{
    extract($args);

    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    $invalid = array();
    if (!isset($invoice_number) || !is_string($invoice_number)) {
        $invalid[] = 'invoice_number';
    } 
    if (!isset($cost) || !is_float($cost)) {
        $invalid[] = 'cost';
    } 
    if (!isset($company_id) || !is_int($company_id)) {
        $invalid[] = 'company_id';
    } 
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1)', join(', ', $invalid));
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
   
    /* Fields in table.
		shipping_id
		invoice_number
		cost
   */
    
    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['reshipping'];
    // Get next ID in table
    $nextId = $dbconn->GenId($table);

    // Add item
    $query = "INSERT INTO $table ("
        . " shipping_id, invoice_number, cost, company_id)"
        . " VALUES (?, ?, ?, ?)";
    $result =& $dbconn->Execute($query, array($nextId, $invoice_number, $cost, $company_id));
    if (!$result) return;
    // Get the ID of the item that we inserted
    $id = $dbconn->PO_Insert_ID($table, 'shipping_id');
    return $id;
}
?>